package com.example.mongodb.mongodb.controller.rabbitmq.delayedqueue.Listener;

import com.rabbitmq.client.Channel;
import io.netty.util.CharsetUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class RabbitmqListener {

    @RabbitListener(queues = "q.delayed")
    public void delayedListener(Message message, Channel channel){
        System.out.println( new String(message.getBody(), CharsetUtil.UTF_8));
        try {
            //消息确认,deliveryTag 改消息的index, multiple ：是否批量确认，true,将一次性ack所有小于 deliveryTag 的消息

            System.out.println(""+message.getMessageProperties().getDeliveryTag());
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
